using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Article;


namespace HengTong.ViewModel.Article.SysArticleCategoryVms
{
    public partial class SysArticleCategoryListVm : BasePagedListVM<SysArticleCategoryView, SysArticleCategorySearcher>
    {

        protected override IEnumerable<IGridColumn<SysArticleCategoryView>> InitGridHeader()
        {
            return new List<GridColumn<SysArticleCategoryView>>{
                this.MakeGridHeader(x => x.CategoryName),
                this.MakeGridHeader(x => x.CategoryCode),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.Icon),
                this.MakeGridHeader(x => x.Color),
                this.MakeGridHeader(x => x.SortOrder),
                this.MakeGridHeader(x => x.IsActive),
                this.MakeGridHeader(x => x.IsVisible),
                this.MakeGridHeader(x => x.ParentName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysArticleCategoryView> GetSearchQuery()
        {
            var query = DC.Set<SysArticleCategory>()
                .CheckEqual(Searcher.IsActive, x=>x.IsActive)
                .CheckEqual(Searcher.IsVisible, x=>x.IsVisible)
                .Select(x => new SysArticleCategoryView
                {
				    ID = x.ID,
                    CategoryName = x.CategoryName,
                    CategoryCode = x.CategoryCode,
                    Description = x.Description,
                    Icon = x.Icon,
                    Color = x.Color,
                    SortOrder = x.SortOrder,
                    IsActive = x.IsActive,
                    IsVisible = x.IsVisible,
                    ParentName = x.Parent.CategoryName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysArticleCategoryView : SysArticleCategory{
        [Display(Name = "分类名称")]
        public String ParentName { get; set; }

    }
}
